﻿using JzSport.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JzSport.WebApp.Init
{
    public partial class Random10Activity4User : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void _ctlBtnCreate_Click(object sender, EventArgs e)
        {
            string phone = this._ctlEditPhone.Text;

            using (JzSportDbContext dbContext = new JzSportDbContext())
            {
                IAccountRepository reps = new AccountRepository(dbContext);
                ActivityRepository aRep = new ActivityRepository(dbContext);
                Account account = reps.GetByPhone(phone);

                for (int index = 0; index < 10; index++)
                {
                    Activity activity = new Activity();
                    activity.Id = Guid.NewGuid();
                    activity.CreatorId = account.Id;
                    activity.CreatedTime = DateTime.Now;
                    activity.CurrentPersonCount = 0;
                    activity.IsFinished = false;

                    activity.Title = string.Format("A{0}", activity.Id.ToString("N").Substring(0, 16));
                    activity.Address = "地址";
                    activity.CategoryCode = "AC002";
                    activity.BeginTime = DateTime.Now;
                    activity.EndTime = DateTime.Now.AddDays(2);
                    activity.MaxPersonCount = 10;
                    activity.CostPrePerson = 100;
                    activity.Descritpion = "description";

                    activity.City = "0";
                    activity.Longitude = new Random().Next(10,100);
                    activity.Latitude = new Random().Next(10, 100);

                    aRep.Create(activity);
                }

                dbContext.SaveChanges();
            }
        }
    }
}